# CMakeLists file for the Chapter 4 Example nr. 05: 
# Example CMake consumer for Config-file package
#
# SPDX-License-Identifier: MIT

cmake_minimum_required(VERSION 3.23)

project(
  ch4_ex07_pack
  VERSION 1.0
  DESCRIPTION "Chapter 4 Example 07, Packaging with CPack"
  LANGUAGES CXX)

if(NOT PROJECT_IS_TOP_LEVEL)
  message(FATAL_ERROR "The chapter-4, ex07_pack project is intended to be a standalone, top-level project. Do not include this directory.")
endif()

add_subdirectory(executable)
add_subdirectory(library)

if(WIN32)
  # if it is a debug build, we want to install debug libraries with the InstallRequiredSystemLibraries module
  if(CMAKE_BUILD_TYPE STREQUAL "Debug")
    set(CMAKE_INSTALL_DEBUG_LIBRARIES TRUE)
  endif()
  # this includes compiler provided runtime libraries on windows
  include(InstallRequiredSystemLibraries)
endif()

# this includes the runtime directories of the executable and the library
install(TARGETS ch4_ex07_executable
        RUNTIME_DEPENDENCIES
        PRE_EXCLUDE_REGEXES "api-ms-.*" "ext-ms-.*"
        POST_EXCLUDE_REGEXES ".*system32/.*\\.dll"
        )

# We will not explicitly specify project name and version here and 
# let CPack to get project name and version from the project()
set(CPACK_PACKAGE_VENDOR "CBP Authors")
# Enable NSIS and TBZ2 generators by default
set(CPACK_GENERATOR "NSIS;TBZ2")
# Use all available cores when parallelism is supported
set(CPACK_THREADS 0) 
# The DEB generator requires CPACK_DEBIAN_PACKAGE_MAINTAINER
# value to be set.
# Enable packaging support for the project
include(CPack)